package com.xiaohai;

import com.xiaohai.myInterface.Imessage;
import com.xiaohai.myfactory.MessageFactory;

import java.lang.reflect.Method;
import java.util.Date;

/**
 * 反射
 */

public class test {

    public static void main(String[] args) throws Exception {
        String msg ="中国加油，武汉加油！疫情终究能够被人们战胜！！！";
        Imessage daheMessage = MessageFactory.getInstance("com.xiaohai.impl.DaheMessage");
        daheMessage.sendMesg(msg);

        Imessage daheMessage2 = MessageFactory.getInstance("com.xiaohai.impl.XuchangMessage");
        daheMessage2.sendMesg(msg);
        daheMessage2.sayHello();
    }



    public void method1() throws Exception{
        Class<?> clas = new Date().getClass();

        //class java.lang.Class
        System.out.println(clas.getClass());
        //java.util.Date
        System.out.println(clas.getName());
        //Date
        System.out.println(clas.getSimpleName());

        Class<?> aClass = Class.forName("java.util.Date");
        Method[] methods = aClass.getMethods();
//        for (Method method : methods) {
//            System.out.println(method);
//
//        }
        Object o = aClass.newInstance();
        Object o1 = aClass.getDeclaredConstructor().newInstance();
        System.out.println(o);;
    }
}
